# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=libsigsegv
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.12
pkgrel=1
pkgdesc="Page fault detection library (mingw-w64)"
arch=('any')
url="https://www.gnu.org/software/libsigsegv/"
license=('GPL2')
source=("${_realname}-${pkgver}.tar.gz"::"https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.gz"
        "0001-libsigsegv-2.11-fix-assembly.patch")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
sha256sums=('3ae1af359eebaa4ffc5896a1aee3568c052c99879316a1ab57f8fe1789c390b6'
            '73d963f144531fad281ca3f4f374c1e328cc505080ef135e8728f114e5aec371')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -Np1 -i "${srcdir}/0001-libsigsegv-2.11-fix-assembly.patch"
  autoreconf -fiv
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
